#import <MJExtension/MJExtension.h>
#import "ZQBaseTablePage.h"
#import "AFNetworkingHelper.h"
#import "UIHelper.h"
#import "ZQBaseModel.h"
#import "ZQBaseCell.h"
static NSString * const ID = @"cell";
@interface ZQBaseTablePage ()
@property (nonatomic , strong) NSMutableArray <ZQBaseModel *> *topics;
@end
@implementation ZQBaseTablePage
- (void)viewDidLoad {
    [super viewDidLoad];
    [UIHelper dismissLoadingInView:nil];

    self.title = _navTitle;
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([ZQBaseCell class]) bundle:nil] forCellReuseIdentifier:ID];
    self.tableView.rowHeight = 180;
    self.tableView.separatorStyle =  UITableViewCellSeparatorStyleNone;
    [self loadNewTopics];
}
- (void)loadNewTopics
{
    AFHTTPSessionManager *mgf = [AFHTTPSessionManager manager];
    NSLog(@"%@",[self backLoadURL]);
    [mgf POST:[self backLoadURL] parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        self.topics = [ZQBaseModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"datalist"]];
            [self.tableView reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
          [UIHelper showErrorWithText:@"网络繁忙,稍后在试" inView:self.view];
    }];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return [NSString stringWithFormat:@"%zd个视频",self.topics.count];
}
- (NSString *)backLoadURL
{
    if (self.pid == ZQBaseKXXL) {
        return @"http://skyapp.mackentan.com/app/v6/playlist.do?pid=149&t=1522826765000&did=UjGblPV7sR7a637ea771&ver=172&it=422984&fit=422984&sign=b8de030ae4a73b697d7a3c8880803b9d26f8481c&appid=com.jediapp.football&idfa=E27CC654-F821-4B04-801C-40098E0D7018";
    }else if (self.pid  == ZQBaseXTZQ) {
                return @"http://skyapp.mackentan.com/app/v6/playlist.do?pid=154&t=1522826826000&did=UjGblPV7sR7a637ea771&ver=172&it=422984&fit=422984&sign=cff91c4a990c0a458032924f9d81896076d4983c&appid=com.jediapp.football&idfa=E27CC654-F821-4B04-801C-40098E0D7018";
    }else if (self.pid == ZQBaseGJJL) {
        return @"http://skyapp.mackentan.com/app/v6/playlist.do?pid=153&t=1522826900000&did=UjGblPV7sR7a637ea771&ver=172&it=422984&fit=422984&sign=6ee7101591471b2f0fb59e736c106fdfc7714e7c&appid=com.jediapp.football&idfa=E27CC654-F821-4B04-801C-40098E0D7018";
    }else if (self.pid  == ZQBaseZQJQ) {
        return @"http://skyapp.mackentan.com/app/v6/playlist.do?pid=152&t=1522826934000&did=UjGblPV7sR7a637ea771&ver=172&it=422984&fit=422984&sign=4ce9188c4024cb3d3068204f61a071fbfa272c8a&appid=com.jediapp.football&idfa=E27CC654-F821-4B04-801C-40098E0D7018";
    }else if (self.pid  == ZQBaseZQGR) {
         return @"http://skyapp.mackentan.com/app/v6/playlist.do?pid=155&t=1522826995000&did=UjGblPV7sR7a637ea771&ver=172&it=422984&fit=422984&sign=e359920b2fd4cda5f870a39d7fa159b34b092f72&appid=com.jediapp.football&idfa=E27CC654-F821-4B04-801C-40098E0D7018";
    }else if (self.pid == ZQBaseMLZQ) {
         return @"http://skyapp.mackentan.com/app/v6/playlist.do?pid=561&t=1522827117000&did=UjGblPV7sR7a637ea771&ver=172&it=422984&fit=422984&sign=d361f757ad39001fc19c6e66b36a7143a02f7139&appid=com.jediapp.football&idfa=E27CC654-F821-4B04-801C-40098E0D7018";
    }else if (self.pid  == ZQBaseWRZJS) {
         return @"http://skyapp.mackentan.com/app/v6/playlist.do?pid=151&t=1522827170000&did=UjGblPV7sR7a637ea771&ver=172&it=422984&fit=422984&sign=8787377621aeaaa1de386e672232c80414925094&appid=com.jediapp.football&idfa=E27CC654-F821-4B04-801C-40098E0D7018";
    }else{
     return @"http://skyapp.mackentan.com/app/v6/playlist.do?pid=150&t=1522827208000&did=UjGblPV7sR7a637ea771&ver=172&it=422984&fit=422984&sign=ef3b8a0f4723040860f9aed617b8de7d8db4d7d4&appid=com.jediapp.football&idfa=E27CC654-F821-4B04-801C-40098E0D7018";
    }
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return  self.topics.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZQBaseCell *cell = [tableView dequeueReusableCellWithIdentifier:ID forIndexPath:indexPath];
    cell.zqBaseModel = self.topics[indexPath.row];
    return cell;
}
@end
